var packageTable;
var edit_btn_template;
var url_table_language;

$(function () {
    //激活页面
    activeMenu("probe-manager");
    //packageTable = initPackageTable();

    $('#packageTable').dataTable(
        {
            "paging": true,
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "info": true,
            "autoWidth": false
        }
    );

    $('#packageGroupTable').dataTable(
        {
            "paging": true,
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "info": true,
            "autoWidth": false
        }
    );

    var packageAdd = $('#package-add');
    packageAdd.click(function () {
        $('#add-package-pop').show();
    });

    var deletePackage = $('.delete-package');
    deletePackage.click(function () {
        $('#confirm-delete-pack-pop').show();
    });

    var packageGroupAdd = $('#package-group-add');
    packageGroupAdd.click(function () {
        $('#add-package-group-pop').show();
    });

    var groupDetail = $('.group-detail');
    groupDetail.click(function () {
        $('#add-package-group-pop').show();
    });

    var groupModify = $('.modify-group');
    groupModify.click(function () {
        $('#add-package-group-pop').show();
    });

    var groupDelete = $('.delete-group');
    groupDelete.click(function () {
        $('#confirm-delete-pack-pop').show();
    });

});

/**
 * 初始化信息总览分页表格
 */
function initPackageTable() {
    return $('#packageTable1').dataTable(
        {
            language: {
                'url': url_table_language
            },
            processing: true, // 进度
            serverSide: true, // 服务器模式
            ordering: false, // 排序
            searching: false, // 搜索
            lengthChange: false, // 切换每页显示条数
            autoWidth: false, // 不自适应宽度
            deferRender: true, // 延迟加载
            stateSave: true, // 保存浏览状态 刷新后还在该页
            paging: false,
            //lengthMenu: [10, 25, 50, 100],
            //pagingType: 'full_numbers',
            // "info": false, // 左下角条数
            columns: [
                {"data": "data.name"},
                {"data": "data.ip"},
                {"data": "data.desc"}
            ],
            columnDefs: [{
                "aTargets": [3],
                "mRender": function (data, type, row) {
                    var editBtn = genBtn(edit_btn_template, {url:"#"});
                    return editBtn;
                }
            }],
            ajax: {
                'url':"/api/getPackageSends",
                'data': function (d) {
                    console.log(d);
                    d.columns = {};
                    return d;
                }
            }
        }
    ).DataTable();
}